using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using G4KFramework.Inputs;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Input.Touch;



namespace G4KFramework.Objects
{
    public class GGuiComponent : GObjectBase
    {
        //---------------------------------------------------------
        // Fields
        protected GGameInput _input = null;

        protected EventHandler _eventTouchTap = null;
        protected EventHandler _eventTouchSlide = null;
        protected EventHandler _eventHold = null;
        protected EventHandler _eventDoubleTap = null;

        private string _actionTouchTap = "TouchTap";
        private string _actionHold = "Hold";
        private string _actionDoubleTap = "DoubleTap";
        private string _actionTouchSlide = "TouchSlide";

        private Vector2 _dimention;

        public Vector2 dimention
        {
            get { return _dimention; }
            set { _dimention = value; }
        }

        //---------------------------------------------------------
        // Properties
        public GGuiComponent(GGameInput input)
        {
            _input = input;
        }

        //---------------------------------------------------------------
        // Set Position
        public void SetPosition(int x, int y)
        {
            _position.X = (float)x;
            _position.Y = (float)y;
        }

        //---------------------------------------------------------------
        // Set Dimention
        public void SetDimention(float width, float high)
        {
            _dimention.X = width;
            _dimention.Y = high;
        }

        public void Update()
        {

        }

        //-------------------------------------------------------------------------------------
        // Register TouchTap Event
        public bool RegisterEventTouchTap(EventHandler eventTouchTap, bool isReleasedPreviously)
        {
            if (_input == null || _dimention.X == 0 || _dimention.Y == 0)
                return false;
            _input.AddTouchTapInput(_actionTouchTap, new Rectangle((int)_position.X, (int)_position.Y, (int)_dimention.X, (int)_dimention.Y), isReleasedPreviously);
            _eventTouchTap = eventTouchTap;
            return true;
        }

        //-------------------------------------------------------------------------------------
        // Register TouchSlide Event
        public bool RegisterEventTouchSlide(EventHandler eventTouchSlide, GInput.Direction direction, float slideDistance)
        {
            if (_input == null || _dimention.X == 0 || _dimention.Y == 0)
                return false;
            _input.AddTouchSlideInput(_actionTouchSlide, direction, slideDistance);
            _eventTouchSlide = eventTouchSlide;
            return true;
        }

        //-------------------------------------------------------------------------------------
        // Register Hold Event
        public bool RegisterEventHold(EventHandler eventHold)
        {
            if (_input == null || _dimention.X == 0 || _dimention.Y == 0)
                return false;
            _input.AddTouchGestureInput(_actionHold, GestureType.Hold, new Rectangle((int)_position.X, (int)_position.Y, (int)_dimention.X, (int)_dimention.Y));
            _eventHold = eventHold;
            return true;
        }

        //-------------------------------------------------------------------------------------
        // Register Double Tap Event
        public bool RegisterEventDoubleTap(EventHandler eventDoubleTap)
        {
            if (_input == null || _dimention.X == 0 || _dimention.Y == 0)
                return false;
            _input.AddTouchGestureInput(_actionDoubleTap, GestureType.DoubleTap, new Rectangle((int)_position.X, (int)_position.Y, (int)_dimention.X, (int)_dimention.Y));
            _eventDoubleTap = eventDoubleTap;
            return true;
        }
    }
}
